from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse

from utils.response_code import RETCODE


class LoginRequiredJSONMixin(LoginRequiredMixin):
    """自定义判断用户是否登录的扩展类：返回JSON"""
    # 'ensure_ascii': False  错误信息以中文形式显示
    def handle_no_permission(self):
        return JsonResponse({'code':RETCODE.SESSIONERR,'errmsg':'用户未登录'},json_dumps_params={'ensure_ascii': False})